home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlib43 / mntlib / strcmp.c < prev    next >
C/C++ Source or Header  |  1993-10-11  |  743b  |  42 lines

  1. /* from Henry Spencer's stringlib */
  2. /* modified by ERS */
  3.  
  4. #include <string.h>
  5. #ifdef __LATTICE__
  6. #undef strcmp
  7. #endif
  8.  
  9. /*
  10.  * strcmp - compare string s1 to s2
  11.  */
  12.  
  13. int                /* <0 for <, 0 for ==, >0 for > */
  14. strcmp(scan1, scan2)
  15. register const char *scan1;
  16. register const char *scan2;
  17. {
  18.     register char c1, c2;
  19.  
  20.     if (!scan1)
  21.         return scan2 ? -1 : 0;
  22.     if (!scan2) return 1;
  23.  
  24.     do {
  25.         c1 = *scan1++; c2 = *scan2++;
  26.     } while (c1 && c1 == c2);
  27.  
  28.     /*
  29.      * The following case analysis is necessary so that characters
  30.      * which look negative collate low against normal characters but
  31.      * high against the end-of-string NUL.
  32.      */
  33.     if (c1 == c2)
  34.         return(0);
  35.     else if (c1 == '\0')
  36.         return(-1);
  37.     else if (c2 == '\0')
  38.         return(1);
  39.     else
  40.         return(c1 - c2);
  41. }
  42.